<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <span @click="$emit('update:delete', [])">全部删除</span>
      <span @click="isiconshow = false">完成</span>
      <van-icon name="delete" @click="isiconshow = true" />
    </van-cell>
    <van-cell
      :title="obj"
      v-for="(obj, index) in Searchhistorys"
      :key="index"
      @click="onsearchclick(obj, index)"
    >
      <van-icon name="close"  v-if="isiconshow" />
    </van-cell>
  </div>
</template>

<script>
export default {
  name: 'SearchHistory',
  props: {
    Searchhistorys: {
      type: Array,
      required: true
    }
  },
  data () {
    return {
      isiconshow: false
    }
  },
  methods: {
    onsearchclick (obj, index) {
      // 如果icon图标是显示的那就删除
      if (this.isiconshow) {
        this.Searchhistorys.splice(index, 1)
      } else {
        // 否则就搜索
        this.$emit('search', obj)
      }
    }
  }
}
</script>

<style scoped lang="less"></style>
